home *** CD-ROM | disk | FTP | other *** search
-
- /* Client routines for Network News Tranfer Protocol ala RFC977 */
-
- #include <stdio.h>
- #include <exec/types.h>
- #include <time.h>
- #include <ctype.h>
- #include <string.h> /* for strchr() */
- #include "global.h"
- #include "timer.h"
- #include "cmdparse.h"
- #include "commands.h"
- #include "socket.h"
- #include "usock.h"
- #include "netuser.h"
- #include "proc.h"
- #include "smtp.h"
- #include "files.h"
- #include "session.h"
- #include "dirutil.h"
- #include "amiga/stat.h"
-
- #define NNTPMAXLEN 512
-
- static struct nntpservers {
- struct timer nntpcli_t;
- char *name;
- int lowtime, hightime; /* for connect window */
- struct nntpservers *next;
- };
-
- #define NULLNNTP (struct nntpservers *)NULL
-
- struct nntpservers *Nntpservers = NULLNNTP;
- static unsigned short nntptrace = 1;
- char respbuf[NNTPMAXLEN];
-
- static void nntptick __ARGS((void *tp));
- static void nntp_job __ARGS((int i1,void *tp,void *v1));
- static int gettxt __ARGS((int s,FILE *fp));
- static int getreply __ARGS((int s));
- static int getarticle __ARGS((int s,long msgid,char *mygroup));
- static int doadds __ARGS((int argc,char *argv[],void *p));
- static int dodrops __ARGS((int argc,char *argv[],void *p));
- static int dokicks __ARGS((int argc,char *argv[],void *p));
- static int dolists __ARGS((int argc,char *argv[],void *p));
- static int donntrace __ARGS((int argc,char *argv[],void *p));
-
- static int donnprofile __ARGS((int argc,char *argv[],void *p));
- static int donnfull __ARGS((int argc,char *argv[],void *p));
- static int donnhost __ARGS((int argc,char *argv[],void *p));
- static int donnorgan __ARGS((int argc,char *argv[],void *p));
- static int donnreply __ARGS((int argc,char *argv[],void *p));
- static int donnsig __ARGS((int argc,char *argv[],void *p));
- static int donnuser __ARGS((int argc,char *argv[],void *p));
- static int donnpost __ARGS((int argc,char *argv[],void *p));
- static int check_blank __ARGS((char *bp));
- static int donntplist __ARGS((int argc,char *argv[],void *p));
- static int donntpkill __ARGS((int argc,char *argv[],void *p));
-
- static char *Puser = NULLCHAR;
- static char *Preply = NULLCHAR;
- static char *Psig = NULLCHAR;
- static char *Porgan = NULLCHAR;
- static char *Pfullname = NULLCHAR;
- static char *Host = NULLCHAR;
-
- /* Tracing levels:
- 0 - no tracing
- 1 - serious errors reported
- 2 - transient errors reported
- 3 - session progress reported
- 4 - actual received articles displayed
- */
-
- static struct cmds Nntpcmds[] = {
- "addserver", doadds, 0, 3, "nntp addserver <nntpserver> <interval>",
- "dropserver", dodrops, 0, 2, "nntp dropserver <nntpserver>",
- "kick", dokicks, 0, 2, "nntp kick <nntpserver>",
- "kill", donntpkill, 0, 2, "nntp kill <jobnumber>",
- "listservers", dolists, 0, 0, NULLCHAR,
- "messages", donntplist, 0, 0, NULLCHAR,
- "profile", donnprofile, 0, 0, NULLCHAR,
- "post", donnpost, 2024, 0, NULLCHAR,
- "trace", donntrace, 0, 0, NULLCHAR,
- NULLCHAR,
- };
-
- int donntp(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc == 1)
- return donntplist(argc,argv,p);
- return subcmd(Nntpcmds,argc,argv,p);
- }
-
- static int doadds(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct nntpservers *np;
- for(np = Nntpservers; np != NULLNNTP; np = np->next)
- if(stricmp(np->name,argv[1]) == 0)
- break;
- if (np == NULLNNTP) {
- np = (struct nntpservers *) callocw(1,sizeof(struct nntpservers));
- np->name = strdup(argv[1]);
- np->next = Nntpservers;
- Nntpservers = np;
- np->lowtime = np->hightime = -1;
- np->nntpcli_t.func = nntptick; /* what to call on timeout */
- np->nntpcli_t.arg = (void *)np;
- }
- if (argc > 3) {
- int i;
- for (i = 3; i < argc; ++i)
- if (isdigit(*argv[i])) {
- int lh, ll, hh, hl;
- sscanf(argv[i], "%d:%d-%d:%d", &lh, &ll, &hh, &hl);
- np->lowtime = lh * 100 + ll;
- np->hightime = hh * 100 + hl;
- }
- }
- /* set timer duration */
- np->nntpcli_t.start = atol(argv[2])*(1000/MSPTICK);
- start_timer(&np->nntpcli_t); /* and fire it up */
- return 0;
- }
-
- static int dodrops(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct nntpservers *np, *npprev = NULLNNTP;
- for(np = Nntpservers; np != NULLNNTP; npprev = np, np = np->next)
- if(stricmp(np->name,argv[1]) == 0) {
- stop_timer(&np->nntpcli_t);
- free(np->name);
- if(npprev != NULLNNTP)
- npprev->next = np->next;
- else
- Nntpservers = np->next;
- free((char *)np);
- return 0;
- }
- tprintf("No such server enabled.\n");
- return 0;
- }
-
- static int dolists(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct nntpservers *np;
- for(np = Nntpservers; np != NULLNNTP; np = np->next) {
- char tbuf[80];
- if (np->lowtime != -1 && np->hightime != -1)
- sprintf(tbuf, " -- %02d:%02d-%02d:%02d", np->lowtime/100, np->lowtime%100, np->hightime/100, np->hightime%100);
- else
- tbuf[0] = '\0';
- tprintf("%-32s (%lu/%lu)\n", np->name,
- read_timer(&np->nntpcli_t) * MSPTICK/1000,
- dur_timer(&np->nntpcli_t) * MSPTICK/1000);
- }
- return 0;
- }
-
- static int donntrace(argc, argv, p)
- int argc;
- char *argv[];
- void *p;
- {
- return setshort(&nntptrace,"NNTP tracing",argc,argv);
- }
-
- static int np_all = 0; /* non-zero if Newsdir is a malloc'ed space */
-
-
- static int dokicks(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct nntpservers *np;
- for(np = Nntpservers; np != NULLNNTP; np = np->next)
- if(stricmp(np->name,argv[1]) == 0) {
- /* If the timer is not running, the timeout function has
- * already been called and we don't want to call it again.
- */
- if(run_timer(&np->nntpcli_t)) {
- stop_timer(&np->nntpcli_t);
- nntptick((void *)np);
- }
- return 0;
- }
- tprintf("No such server enabled.\n");
- return 0;
- }
-
- /* This is the routine that gets called every so often to connect to
- * NNTP servers.
- */
- static void nntptick(tp)
- void *tp;
- {
- newproc("NNTP client", 3072, nntp_job, 0, tp, NULL);
- }
-
- static void nntp_job(i1,tp,v1)
- int i1;
- void *tp, *v1;
- {
- FILE *wfile, *tfile, *xfile;
- char *cp, *cp1,
- wfilename[13], nnfix[9], xtmp[LINELEN], wtmp[LINELEN],
- ttmp[LINELEN], wgroup[80], mygroup[80], wmsgid[80];
- int s, i, code, now;
- long articles, first, last, mylast;
- struct tm *ltm;
- time_t t;
- struct nntpservers *np = (struct nntpservers *) tp;
- struct sockaddr_in fsocket;
-
- if (nntptrace >= 2)
- mainlog(-1,"NNTP Checking NewsGroups on \"%s\"",np->name);
- if(availmem() < Memthresh){
- if (nntptrace >= 2)
- mainlog(-1,"NNTP daemon quit -- low memory");
- /* Memory is tight, don't do anything */
- start_timer(&np->nntpcli_t);
- return;
- }
-
- time(&t); /* more portable than gettime() */
- ltm = localtime(&t);
- now = ltm->tm_hour * 100 + ltm->tm_min;
- if (np->lowtime < np->hightime) { /* doesn't cross midnight */
- if (now < np->lowtime || now >= np->hightime) {
- if (nntptrace >= 3)
- mainlog(-1,"NNTP window to '%s' not open", np->name);
- start_timer(&np->nntpcli_t);
- return;
- }
- } else {
- if (now < np->lowtime && now >= np->hightime) {
- if (nntptrace >= 3)
- mainlog(-1,"NNTP window to '%s' not open", np->name);
- start_timer(&np->nntpcli_t);
- return;
- }
- }
-
- fsocket.sin_addr.s_addr = resolve(np->name);
- if(fsocket.sin_addr.s_addr == 0) { /* No IP address found */
- if (nntptrace >= 2)
- mainlog(-1,"NNTP can't resolve host \"%s\"", np->name);
- /* Try again later */
- start_timer(&np->nntpcli_t);
- return;
- }
- fsocket.sin_family = AF_INET;
- fsocket.sin_port = IPPORT_NNTP;
-
- s = socket(AF_INET,SOCK_STREAM,0);
- /* sockmode(s,SOCK_ASCII); */
- if(connect(s,(char *)&fsocket,SOCKSIZE) == -1){
- cp = sockerr(s);
- mainlog(-1,"NNTP %s Connect failed: %s",psocket(&fsocket),
- cp != NULLCHAR ? cp : "");
- goto quit;
- }
- /* Eat the banner */
- i = getreply(s);
- if(i >= 400) {
- mainlog(-1,"NNTP %s bad reply on banner (response was %d)",psocket(&fsocket),i);
- goto quit;
- }
-
- if(i == 201) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP - No posting allowed on \"%s\"", np->name);
- } else {
- for(filedir(Newsqueue,0,wfilename); wfilename[0] != '\0';
- filedir(Newsqueue,1,wfilename)) {
-
- cp = wfilename;
- cp1 = nnfix;
- while (*cp && *cp != '.')
- *cp1++ = *cp++;
- *cp1 = '\0';
-
- sprintf(wtmp,"%s/%s",Newsdir,wfilename);
- if ((wfile = fopen(wtmp,READ_TEXT)) == NULLFILE)
- continue;
- (void) fgets(wgroup,LINELEN,wfile); /* read target group */
- rip(wgroup);
- (void) fgets(wmsgid,LINELEN,wfile); /* read messageid */
- rip(wmsgid);
- fclose(wfile);
-
- if (nntptrace >= 3)
- mainlog(-1,"==>GROUP %s", wgroup);
- usprintf(s,"GROUP %s\n", wgroup);
- i = getreply(s);
- if(i == 411) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP No Such Newsgroup '%s'",wgroup);
- continue;
- }
- if(i == 211) {
- if (nntptrace >= 3)
- mainlog(-1,"==>POST");
- usprintf(s,"POST\n");
- i = getreply(s);
- if(i == 340) { /* Send It */
- sprintf(ttmp,"%s/%s.txt", Newsdir, nnfix);
- if((tfile = fopen(ttmp, READ_TEXT)) != NULLFILE) {
- while(fgets(ttmp, LINELEN, tfile) != NULLCHAR)
- usprintf(s,ttmp);
- fclose(tfile);
- }
- i = getreply(s);
- if(i == 240)
- remove(wtmp);
- }
- if(i == 440)
- if (nntptrace >= 1)
- mainlog(-1,"NNTP Posting not allowed");
- if(i == 441)
- if (nntptrace >= 1)
- mainlog(-1,"NNTP Transfer failed");
- }
- }
- }
-
- /*=============== COLLECT NEWS (testing !) =====================*/
- sprintf(wtmp,"%s/Groups",Newsdir);
- if ((wfile = fopen(wtmp,READ_TEXT)) == NULLFILE) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP NewsGroup Control file not found");
- goto quit;
- }
-
- sprintf(xtmp,"%s/Groups.New",Newsdir);
- if ((xfile = fopen(xtmp,WRITE_TEXT)) == NULLFILE) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP Unable to open Backup NewsGroup file");
- goto quit;
- }
-
- while (fgets(wgroup,LINELEN,wfile) != NULLCHAR) { /* read target group */
- rip(wgroup);
- sscanf(wgroup,"%ld %s", &mylast, &mygroup);
- if (mygroup == NULLCHAR)
- goto quit;
-
- if (nntptrace >= 3)
- mainlog(-1,"==>GROUP %s", mygroup);
- usprintf(s,"GROUP %s\n", mygroup);
- i = getreply(s);
-
- if(i == 411) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP No Such Newsgroup '%s'",mygroup);
- continue;
- }
- if(i == 211) {
- sscanf(respbuf,"%d %ld %ld %ld ", &code, &articles, &first, &last);
-
- mainlog(-1, "First ( %ld ) - Last ( %ld ) - MyLast ( %ld )",
- first, last, mylast);
-
- if(mylast<=first) mylast=--first;
-
- while (++mylast <= last) {
- mainlog(-1,"NNTP Retrieving '%ld'", mylast);
- if(getarticle(s,mylast,mygroup) == -1)
- mainlog(-1,"NNTP Gave up with article '%ld'", mylast);
- }
- }
-
- fprintf(xfile,"%ld %s\n", --mylast, mygroup);
-
- continue;
- }
-
- quit:
- if (nntptrace >= 3)
- mainlog(-1,"==>QUIT");
- usprintf(s,"QUIT\n");
- /* Eat the response */
- getreply(s);
- if (nntptrace >= 2)
- mainlog(-1,"NNTP Finished with \"%s\"", np->name);
- close_s(s);
-
- fclose(wfile);
- fclose(xfile);
-
- unlink(wtmp);
- rename(xtmp,wtmp);
-
- /* Restart timer */
- start_timer(&np->nntpcli_t);
-
- return;
- }
-
- static int gettxt(s,fp)
- int s;
- FILE *fp;
- {
- char buf[NNTPMAXLEN];
- int nlines;
-
- for (nlines = 0; recvline(s,buf,NNTPMAXLEN) != -1; ++nlines) {
- if(strcmp(buf,".\n") == 0) {
- if (nntptrace >= 3)
- mainlog(-1,"NNTP received %d lines", nlines);
- return 0;
- }
- /* check for escaped '.' characters */
- if(strcmp(buf,"..\n") == 0)
- fputs(".\n",fp);
- else
- fputs(buf,fp);
- if (nntptrace >= 4) {
- rip(buf); /* so that the log entries don't have an extra CR */
- mainlog(-1,"<==%s", buf);
- }
- }
- if (nntptrace >= 1)
- mainlog(-1,"NNTP receive error after %d lines", nlines);
- return -1;
- }
-
- static int getreply(s)
- int s;
- {
- int response;
-
- while(recvline(s,respbuf,NNTPMAXLEN) != -1) {
- /* skip informative messages and blank lines */
- if(respbuf[0] == '\0' || respbuf[0] == '1' || respbuf[0] == '5')
- continue;
- rip(respbuf);
- sscanf(respbuf,"%d",&response);
- if (nntptrace >= 3)
- mainlog(-1,"<==%s", respbuf);
- return response;
- }
- if (nntptrace >= 3)
- mainlog(-1,"==No response");
- return -1;
- }
-
- static int getarticle(s,msgid,mygroup)
- int s;
- long msgid;
- char *mygroup;
- {
- char buf[NNTPMAXLEN], froml[NNTPMAXLEN], *cp;
- FILE *fp, *tmpf;
- int i;
-
- if (nntptrace >= 3)
- mainlog(-1,"==>ARTICLE %ld", msgid);
- usprintf(s,"ARTICLE %ld\n", msgid);
- i = getreply(s);
-
- if(i == -1 || i >= 500)
- return -1;
- if(i >= 400)
- return 0;
-
- if((tmpf = tmpfile()) == NULLFILE) {
- if (nntptrace >= 1)
- mainlog(-1,"NNTP Cannot open temp file for article");
- return -1;
- }
- if(gettxt(s,tmpf) == -1) {
- fclose(tmpf);
- return -1;
- }
-
- /* convert the article into mail format */
- rewind(tmpf);
- froml[0] = '\0';
- while(fgets(buf,NNTPMAXLEN,tmpf) != NULLCHAR) {
- if(strncmp(buf,"From: ",6) == 0) {
- time_t t;
- rip(&buf[6]);
- time(&t);
- sprintf(froml,"From %s %s",&buf[6], ctime(&t));
- }
- /* invalid article - missing 'From:' line */
- if(strcmp(buf,"\n") == 0 && froml[0] == '\0' ) {
- fclose(tmpf);
- break;
- }
- }
-
- sprintf(buf, "%s/%s", Mailspool, mygroup);
-
- /* This bit is supposed to create a directory chain and then tag .txt */
- /* on to the end , i.e xx.yy.zz becomes xx/yy/zz.txt */
- for(cp = buf;*cp != '\0';cp++)
- if (*cp == '.' ) {
- *cp = '\0';
- mkdir(buf);
- *cp = '/';
- }
- strcat(buf, ".txt");
- /* ------------------------------------------------------------------- */
-
- /* open the mail file */
- printf("Writing article to '%s'\n", buf);
- if((fp = fopen(buf,APPEND_TEXT)) != NULLFILE) {
- fputs(froml,fp);
- rewind(tmpf);
- while(fgets(buf,NNTPMAXLEN,tmpf) != NULLCHAR) {
- /* for UNIX mail compatiblity */
- if(strncmp(buf,"From ",5) == 0)
- putc('>',fp);
- fputs(buf,fp);
- }
- putc('\n',fp);
- fclose(fp);
- }
-
- fclose(tmpf);
-
- return 0;
- }
-
- /* -------------------- Profile subcmds -------------------- */
-
- static int donnuser(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Puser);
- else {
- free(Puser);
- Puser = strdup(argv[1]);
- }
- return 0;
- }
-
- static int donnsig(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Psig);
- else {
- if(access(argv[1],0) == 0) {
- free(Psig);
- Psig = strdup(argv[1]);
- } else {
- tputs("No such signature file\n");
- return -1;
- }
- }
- return 0;
- }
-
- static int donnfull(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Pfullname);
- else {
- free(Pfullname);
- Pfullname = strdup(argv[1]);
- }
- return 0;
- }
-
- static int donnhost(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Host);
- else {
- free(Host);
- Host = strdup(argv[1]);
- }
- return 0;
- }
-
- static int donnorgan(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Porgan);
- else {
- free(Porgan);
- Porgan = strdup(argv[1]);
- }
- return 0;
- }
-
- static int donnreply(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc < 2)
- tprintf("%s\n",Preply);
- else {
- free(Preply);
- Preply = strdup(argv[1]);
- }
- return 0;
- }
-
- struct cmds Prof[] = {
- "fullname", donnfull, 0, 0, NULLCHAR,
- "host", donnhost, 0, 0, NULLCHAR,
- "organ", donnorgan, 0, 0, NULLCHAR,
- "reply", donnreply, 0, 0, NULLCHAR,
- "sig", donnsig, 0, 0, NULLCHAR,
- "user", donnuser, 0, 0, NULLCHAR,
- NULLCHAR,
- };
-
- /* subcmd parser */
- static int donnprofile(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- if(argc == 1) {
- if (Host == NULLCHAR) {
- Host = strdup(Hostname);
- }
-
- if (Host != NULLCHAR)
- tprintf("Hostname : %s\n",Host);
- if (Pfullname != NULLCHAR)
- tprintf("Full Name : %s\n",Pfullname);
- if (Porgan != NULLCHAR)
- tprintf("Organisation : %s\n",Porgan);
- if (Preply != NULLCHAR)
- tprintf("Reply-To : %s\n",Preply);
- if (Psig != NULLCHAR)
- tprintf("Signature : %s\n",Psig);
- if (Puser != NULLCHAR)
- tprintf("User Name : %s\n",Puser);
-
- return 0;
- }
- return subcmd(Prof,argc,argv,p);
- }
-
- /* manually entering new news
- * returncode: -1 if error; 0 success */
- static int donnpost(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- struct session *sp;
- char buf[NNTPMAXLEN], pbuf[80], qbuf[80];
- int id;
- long currtime;
- FILE *idf, *ufp, *fp, *fq;
-
- if((sp = newsession("Post",POST,0)) == NULLSESSION) {
- tprintf("Too many sessions\n");
- freeargs(argc,argv);
- return 1;
- }
-
- for (;;) {
- id = get_msgid();
-
- sprintf(pbuf,"%s/%d.txt",Newsdir,id);
- fp = fopen(pbuf,WRITE_TEXT);
- sprintf(qbuf,"%s/%d.wrk",Newsdir,id);
- fq = fopen(qbuf,WRITE_TEXT);
-
- if (Puser == NULLCHAR) {
- tprintf("User name? ");
- recvline(sp->input,buf,NNTPMAXLEN);
- rip(buf);
- if (check_blank(buf)) {
- fclose(fp);
- fclose(fq);
- remove(pbuf);
- remove(qbuf);
- goto done;
- }
- Puser = strdup(buf);
- }
-
- fprintf(fp,"Path: %s\n",Host);
- fprintf(fp,"From: %s@%s",Puser,Hostname);
-
- if (Pfullname != NULLCHAR)
- fprintf(fp," (%s )",Pfullname);
- fprintf(fp,"\n");
-
- tprintf("Newsgroup? ");
- recvline(sp->input,buf,NNTPMAXLEN);
- rip(buf);
- if (check_blank(buf)) {
- fclose(fp);
- fclose(fq);
- remove(pbuf);
- remove(qbuf);
- goto done;
- }
- fprintf(fp,"Newsgroups: %s\n",buf);
- fprintf(fq,"%s\n",buf);
-
- tprintf("Subject? ");
- recvline(sp->input,buf,NNTPMAXLEN);
- rip(buf);
- if (!check_blank(buf))
- fprintf(fp,"Subject: %s\n",buf);
- fprintf(fp,"Message-Id: <%d@%s>\n",id,Hostname);
- fprintf(fq,"<%d@%s>\n",id,Hostname);
- time(&currtime);
- fprintf(fp,"Date: %s",ptime(&currtime));
- fprintf(fp,"Sender: NNTP@%s\n",Hostname);
-
- if (Preply != NULLCHAR)
- fprintf(fp,"Reply-To: %s\n",Preply);
-
- if (Porgan != NULLCHAR)
- fprintf(fp,"Organization: %s\n",Porgan);
-
- fprintf(fp, "Comment: AmigaNOS v%s\n", Version);
-
- fprintf(fp,"\n");
- tputs("Enter message - end with . or /EX ('.r' or '.u' to upload)\n");
-
- for (;;) {
- recvline(sp->input,buf,NNTPMAXLEN);
- if(strcmp(buf,".u\n") == 0 || strcmp(buf,".r\n") == 0) {
- tputs("Filename? ");
- recvline(sp->input, buf, LINELEN);
- rip(buf);
- if((ufp = fopen(buf, READ_TEXT)) != NULLFILE) {
- while(fgets(buf, NNTPMAXLEN, ufp) != NULL)
- fputs(buf, fp);
- fclose(ufp);
- }
- tputs("(continue)\n");
- }
- if(strcmp(buf,".\n") == 0 ||
- strcmpi(buf,"***END\n") == 0 ||
- strcmpi(buf,"/EX\n") == 0)
- break;
- fprintf(fp,"%s",buf);
- }
-
- if (Psig != NULLCHAR) {
- sprintf(buf,"%s",Psig);
- if ((idf = fopen(buf,READ_TEXT)) != NULLFILE ) {
- while(fgets(buf,NNTPMAXLEN,idf) != NULL)
- fprintf(fp,"%s",buf);
- fclose(idf);
- }
- }
-
- loop:
- fprintf(fp,"\n.\n");
-
- fclose(fp);
- fclose(fq);
-
- tprintf("Post another? ");
- recvline(sp->input,buf,NNTPMAXLEN);
- if (tolower(buf[0]) == 'n')
- goto done;
- }
-
- done:
- freesession(sp);
- return 0;
- }
-
- /* checks for not valid chars in a line
- * returncode: 0 if valid; 1 if invalid */
- static int check_blank(bp)
- char *bp;
- {
- if (strpbrk(bp, "!@#$%^&*()_+=<>,./?~`[]{}\|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") == NULL)
- return 1;
- return 0;
- }
-
- /* list messages wating to be sent */
- static int donntplist(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- char tstring[80], line[20],
- group[LINELEN], *cp;
- struct stat stbuf;
- struct tm *tminfo, *localtime();
- FILE *fp;
-
- Current->flowmode = 1; /* Enable the more mechanism */
- tprintf(" Job Size Date Time Group\n");
- filedir(Newsqueue,0,line);
- while(line[0] != '\0') {
- sprintf(tstring,"%s/%s",Newsdir,line);
- if ((fp = fopen(tstring,READ_TEXT)) == NULLFILE) {
- tprintf("Can't open %s: %s\n",tstring,sys_errlist[errno]);
- continue;
- }
- if ((cp = strrchr(line,'.')) != NULLCHAR)
- *cp = '\0';
- sprintf(tstring,"%s/%s.txt",Newsdir,line);
- stat(tstring,&stbuf);
- tminfo = localtime(&stbuf.st_ctime);
- fgets(group,sizeof(group),fp);
- rip(group);
- tprintf("%7s %7ld %02d/%02d %02d:%02d %-25s\n",
- line, stbuf.st_size,
- tminfo->tm_mon+1, tminfo->tm_mday, tminfo->tm_hour,
- tminfo->tm_min, group);
- (void) fclose(fp);
- pwait(NULL);
- filedir(Newsqueue,1,line);
- }
- Current->flowmode = 0;
- return 0;
- }
-
- /* kill a job in the mqueue */
- static int donntpkill(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- char s[LINELEN];
- char *cp;
-
- sprintf(s,"%s/%s.wrk",Newsdir,argv[1]);
- cp = strrchr(s,'.');
- if (remove(s))
- tprintf("Job id %s not found\n",argv[1]);
- strcpy(cp,".txt");
- (void) remove(s);
- return 0;
- }
-
-